import math
import random

'''打印Hello,World!'''
# print ('Hello,World!')

'''打开文件打字'''
# file = open('C:/Users/Hello/Desktop/test.txt','w')
# file.write('hello, world')

'''字符串拼接'''
# what_he_does = ' plays '
# his_instrument = 'guitar'
# his_name = 'Robert Johonson'
# artist_intro = his_name + what_he_does + his_instrument
# print(artist_intro)

'''字符串类型和数字拼接'''
# num = 1
# string = '1'
# print(num + int(string))
# print(str(num) + string)

'''字符串相乘例子1'''
# words = 'words ' * 3
# print(words)

'''字符串相乘例子2'''
# word = 'a loooooong word'
# num = 12
# string = 'bang!'
# total = string * (len(word) - num)
# print((len(word) - num))
# print(total)

'''字符串切片'''
# name = 'My name is Mikener'
# print(name[0])
# print(name[0:])
# print(name[0:len(name)])
# print(name[11::2])
# print(name[11:15])
# print(name[5:])
# print(name[:5])
# print(name[:5])
# print(name[-2])

'''找出你朋友中的魔鬼'''
# word = 'friends'
# find_the_evil_in_your_friends = word[0] + word[2:4] + word[-3:-1]
# print(find_the_evil_in_your_friends)

'''遮挡信息'''
# phone_number = '1286-666-0006'
# hiding_number = phone_number.replace(phone_number[:9], '*' * 9)
# print(hiding_number)

'''搜索字符串'''
# search = '168'
# num_a = '1386-168-0006'
# num_b = '1681-222-0006'
# print(search + ' is at ' + str(num_a.find(search)) + ' to ' + str(num_a.find(search) + len(search)) + ' of num_a')
# print(search + ' is at ' + str(num_b.find(search)) + ' to ' + str(num_b.find(search) + len(search)) + ' of num_b')

'''定义函数'''

# def fahrenheit_converter(C):
#     fahrenheit = C * 9 / 5 + 32
#     return str(fahrenheit) + '℉'
#
#
# def celsius_converter(F):
#     celsius = (F - 32) * 5 / 9
#     return str(celsius) + "℃"
#
#
# human_degree = fahrenheit_converter(37)
# print(human_degree)
# print(celsius_converter(float(human_degree[0:len(human_degree) - 1])))
#
# f_451 = celsius_converter(451)
# print(f_451)


'''g转换为kg 方法1'''

# def g_to_kg():
#     kg = input('请输入重量，按e退出')
#     if kg == 'e':
#         print('谢谢使用')
#         exit(0)
#     if int(kg) > 0:
#         print(int(kg) / 1000, 'kg')
#     else:
#         return "输入为负数"

'''g转换为kg 方法2'''
# def g_to_kg2():
#     flag = True
#     while flag:
#         kg = input('请输入重量，按e退出')
#         if kg == 'e':
#             flag = False
#         elif int(kg) < 0:
#             print("输入为负数,请重新输入")
#         else:
#             print(int(kg) / 1000, 'kg')
#
#
# if __name__ == '__main__':
#     g_to_kg2()

'''求一个三角形的最长边'''

# def long_edge():
#     a = eval(input('请输入边长a'))
#     b = eval(input('请输入边长b'))
#     print("边长c为", math.sqrt(math.pow(a, 2) + math.pow(b, 2)))
#
#
# if __name__ == '__main__':
#     long_edge()

# python的变量作用域：
# 模块对应global，
# 最内层为local，
# 外层为nonlocal
# 变量查找顺序：内层作用域->外层->全局->builtin
# 只有class、def和lamda会改变作用域
#
# 读取变量的时候，如果local没有，查找nonlocal，然后global
# 写变量的时候，如果没有指明nonlocal/global, 就是在局部作用域定义一个新的变量

# def text_create(name_s, msg):
#     """
#     :param name_s:
#     :param msg:
#     :return:
#     """
#     desktop_path = 'C:/Users/Hello/Desktop/'
#     full_path = desktop_path + name_s + '.txt'
#     file = open(full_path, 'w')
#     file.write(msg)
#     print('Done')
#     pass
#
#
# text_create('hello', 'HelloWorld')
#
#
# def text_filter(word, censord_word='lame', change_word='Awesome'):
#     new_word = str(word).replace(censord_word, change_word)
#     print(new_word)
#     return new_word
#
#
# word = 'Python is lame!'
# text_filter(word)

'''在终端里面定义>>> def hehe():
...     hehe = '123'
...     print(hehe)
...
>>> hehe()
123'''

'''容器'''

# album = []
# album = ['Black Star', 'David Bowie', 25, True]
# album.append('new song')
# print(album)
# print(album[0])
# print(album[4])
# print(album[-5])
# print(album[-1])
# print(25 in album)
#
# the_Eddie = 'Eddie'
# name = 'Eddie'
# the_Eddie == name
# print(the_Eddie is name)
#
# bool(0)
# bool([])
# bool('')
# bool(False)
# bool(None)

# print((1 < 3) and (2 > 3))
# print(not 1 > 100)
# print((1 < 3) or (2 > 3))

# def account_login():
#     password = input('Password:')
#     if password == '123456':
#         print('Login success!')
#     else:
#         print("Wrong password or invalid input!")
#         account_login()
#
# account_login()
'''输入密码例子'''
# password_list = ['*#*#', '12345']
#
#
# def account_login():
#     password = input('Password:')
#     password_correct = password in password_list and (not password == '*#*#')
#     password_reset = password == password_list[0]
#     if password_correct:
#         print('Login success!')
#     elif password_reset:
#         new_password = input('Enter a new password:')
#         password_list.append(new_password)
#         print('Your password has changed successfully!')
#         print(password_list)
#         account_login()
#     else:
#         print('Wrong password or invalid input!')
#         account_login()
#
#
# account_login()
'''循环例子'''
# for every_letter in 'Hello world':
#     print(every_letter)

# for num in range(1, 11):
#     print(str(num) + ' + 1 =', num + 1)

# songlist = ['Holy Diver', 'Thunderstruck', 'Rebel Rebel']
# for song in songlist:
#     if song == 'Holy Diver':
#         print(song, ' - Dio')
#     elif song == 'Thunderstruck':
#         print(song, ' - AC/Dc')
#     elif song == 'Rebel Rebel':
#         print(song, ' - David Bowie')

# for i in range(1,10):
#     for j in range(1,10):
#         print("{} x {} = {}".format(i, j, i * j))

# while 1 < 3:
#     print('1 is smualler than 3')

# count = 0
# while True:
#     print('Repeat this line!')
#     count = count + 1
#     if count == 5:
#         break

'''三次输入错误不允许输入'''

# pass_word_list = ['*#*#', '12345']
#
# def do_login():
#     tries = 3
#     while tries > 0:
#         print(tries)
#         password = input('Password:')
#         password_correct = password == pass_word_list[-1]
#         password_reset = password == pass_word_list[0]
#         if  password_correct:
#             print('Login success!')
#             break
#         elif password_reset:
#             new_password = input('Enter a new password:')
#             pass_word_list.append(new_password)
#             print('账号已经修改')
#             do_login()
#             break
#
#         else:
#             print('Wrong password or invalid input!')
#             tries = tries - 1
#             print("您还剩下{}次机会".format(tries))
#     else:
#         print('您的账号被锁定')
#
# do_login()

'''桌面上循环创建10个文件'''

# def ten_file():
#     time = 10
#     while time > 0:
#         file_name = str(time) + '.txt'
#         file = open(file_name, 'w')
#         file.write('hello, world')
#         time -= 1
#
#
# ten_file()

'''复利'''

# def invest():
#     print('principal amount: 100')
#     year = 1
#     while year < 9:
#         f = 100 * math.pow((1.00 + 0.05), year)
#         print('year {}:${}'.format(year, f))
#         year += 1
#
#
# invest()

'''偶数'''

# def oushu():
#     for i in range(1, 101):
#         if i % 2 == 0:
#             print(i)
#
#
# oushu()

'''打印1到3的和'''
# a_list = [1,2,3]
# print(sum(a_list))

'''随机函数'''

# point1 = random.randrange(1,7)
# point2 = random.randrange(1,7)
# point3 = random.randrange(1,7)
#
# print(point1, point2, point3)

''' 摇色子'''

# def roll_dice(numbers=3, points=None):
#     if points is None:
#         points = []
#     while numbers > 0:
#         point = random.randrange(1, 7)
#         points.append(point)
#         numbers -= 1
#     return points
# 
# 
# def is_big_small(point):
#     if 3 <= point <= 10:
#         print('结果是小')
#         return '小'
#     elif 11 <= point <= 18:
#         print('结果是大')
#         return '大'
# 
# 
# def is_money_over():
#     global money
#     print('money:', money)
#     start_game()
#     if money > 0:
#         print('您还剩下{}元'.format(money))
#     elif money == 0:
#         print('您还剩下{}元'.format(money))
#         print('钱用完了，游戏结束')
#     else:
#         print('您欠下{}元的债'.format(abs(money)))
# 
# 
# def start_game():
#     global money
#     print('游戏开始')
#     input_set = ['大', '小']
#     user_input = input('赌大赌小?')
#     user_money = eval(input('请下赌注'))
#     if user_input in input_set:
#         if str(user_money).isdigit():
#             if user_money > 0:
#                 points = roll_dice()
#                 print(points)
#                 point_sum = sum(points)
#                 real_value = is_big_small(point_sum)
#                 if user_input == real_value:
#                     print('猜对了')
#                     money = money + user_money
#                     is_money_over()
#                 else:
#                     print('猜错了')
#                     money = money - user_money
#                     is_money_over()
#                 # if user_money <= money:
#                 #     points = roll_dice()
#                 #     print(points)
#                 #     point_sum = sum(points)
#                 #     real_value = is_big_small(point_sum)
#                 #     if user_input == real_value:
#                 #         print('猜对了')
#                 #         money = money + user_money
#                 #     else:
#                 #         print('猜错了')
#                 #         money = money - user_money
#                 #         is_money_over()
#                 # else:
#                 #     print('您下的赌注，比您的资金量大')
#                 #     is_money_over()
#             else:
#                 print('不能输入0或负数')
#                 is_money_over()
#         else:
#             print('输入非法，重新开始')
#             is_money_over()
#     else:
#         print('输入非法，重新开始')
#         is_money_over()
# 
# 
# if __name__ == '__main__':
#     money = 1000
#     start_game()


'''检测输入电话号码'''

# CN_mobile = [134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 199, 147, 178, 1705]
# CN_union = [130, 131, 132, 155, 156, 185, 186, 145, 176, 1709]
# CN_telecom = ['133', '153', '180', '181', '189', '177', '1700']
#
#
# def checkPhoneNum():
#     phone = input('请输入您的手机号')
#     if phone.isdigit():
#         if len(phone) == 11:
#             if phone[0:3] in CN_telecom or phone[0:3] in CN_union or phone[0:3] in CN_mobile:
#                 print('正确的手机号')
#         else:
#             print('手机号位数不对')
#     else:
#         print('输入的手机号只能包含数字')
#
#
# if __name__ == '__main__':
#     checkPhoneNum()

'''列表的增删改查'''
fruit = ['pineapple','pear']
fruit.insert(1, 'grape')
print(fruit)

fruit[0:0] = ['0orange']
print(fruit)
fruit.remove('grape')
print(fruit)
fruit[0] = 'replace'
print(fruit)
del fruit[0:2]
print(fruit)

NASDAQ_ocde = {
    'BIDU' : 'Baidu',
    'SINA' : 'sina',
    'YOKU' : 'Youku'
}
print(NASDAQ_ocde['YOKU'])
a = {'key': '123', 'key': '456'}
print(a)
NASDAQ_ocde['YOKU'] = 'youguan_ali'
print(NASDAQ_ocde)
NASDAQ_ocde.update({'FB':'Facebook','TSLA':'Tesla'})
print(NASDAQ_ocde)
del NASDAQ_ocde['FB']
print(NASDAQ_ocde)


'''元组'''
letter = ('a','b','c','d','e','f','g')
print(letter[0])

'''集合'''
a_set = {1,2,3,4}
a_set.add(5)
a_set.discard(2)
print(a_set)

num_list = [6,2,7,4,1,3,5]
print(sorted(num_list))
